package com.otv.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

@Entity
@Table(name="nomenclature")
public class Nomenclature {
	
	private Long id;
	private String nom; 
	private String code;
	private Nomenclature supNomenclature;
    private NiveauNomenclature niveauNomenclature;
    private Set<Nomenclature> lst_nomenclature = new HashSet<Nomenclature>();
    
    @Id
	@GeneratedValue (strategy = GenerationType.AUTO)
	@Column(name="id", unique = true, nullable = false)
	public Long getId() {
		return id;
	}
    
	public void setId(Long id) {
		this.id = id;
	}
	
	@Column(name="nom")
	public String getNom() {
		return nom;
	}
	public void setNom(String nom) {
		this.nom = nom;
	}
	
	@Column(name="code")
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	
	@ManyToOne()
	@JoinColumn(name="idSupHier", nullable=true)
	public Nomenclature getSupNomenclature() {
		return supNomenclature;
	}
	public void setSupNomenclature(Nomenclature supNomenclature) {
		this.supNomenclature = supNomenclature;
	}
	
	@ManyToOne()
	@JoinColumn(name="idLevel")
	public NiveauNomenclature getNiveauNomenclature() {
		return niveauNomenclature;
	}
	
	public void setNiveauNomenclature(NiveauNomenclature niveauNomenclature) {
		this.niveauNomenclature = niveauNomenclature;
	}
	
	@OneToMany(targetEntity = Nomenclature.class,cascade= CascadeType.ALL, mappedBy = "supNomenclature",fetch = FetchType.EAGER, orphanRemoval = true)
	public Set<Nomenclature> getLst_nomenclature() {
		return lst_nomenclature;
	}
	public void setLst_nomenclature(Set<Nomenclature> lst_nomenclature) {
		this.lst_nomenclature = lst_nomenclature;
	}
}
